# Maintainer: Alexey Pavlov <Alexpux@gmail.com>

pkgbase=libgpg-error
pkgname=('libgpg-error' 'libgpg-error-devel') # 'gpg-error'
pkgver=1.20
pkgrel=1
pkgdesc="Support library for libgcrypt"
arch=(i686 x86_64)
url="http://www.gnupg.org"
license=('LGPL')
depends=('msys2-runtime' 'sh' 'libiconv' 'libintl')
makedepends=('libiconv-devel' 'gettext-devel')
source=(ftp://ftp.gnupg.org/gcrypt/libgpg-error/${pkgname}-${pkgver}.tar.bz2{,.sig}
        #ftp://ftp.franken.de/pub/crypt/mirror/ftp.gnupg.org/gcrypt/libgpg-error/${pkgname}-${pkgver}.tar.bz2
        libgpg-error-1.16-msys2.patch
        cygwin-gen-lock2.patch)
sha1sums=('89c961f63469739fe816a56dcdd86c2e1897cace'
          'SKIP'
          '9c191dab67f4cf73410c33e1f2d3caecba1c7eae'
          '24f90e2f7f86b06dd9e60884c92f2a89320849ea')

prepare() {
  cd "$srcdir/$pkgname-$pkgver"

  patch -p1 -i ${srcdir}/libgpg-error-1.16-msys2.patch
  patch -p1 -i ${srcdir}/cygwin-gen-lock2.patch
  autoreconf -fi
}

build() {
  cd "${srcdir}"/${pkgname}-${pkgver}
  ./configure \
    --prefix=/usr \
    --build=${CHOST} \
    --without-libiconv-prefix \
    --without-libintl-prefix \
    --enable-shared \
    --enable-static

  make V=1 no_undefined=-no-undefined
  make DESTDIR="${srcdir}/dest" install
}

check() {
  cd ${srcdir}/${pkgname}-${pkgver}
  make check
}

package_libgpg-error() {
  groups=('libraries')

  mkdir -p ${pkgdir}/usr/share
  cp -rf ${srcdir}/dest/usr/bin ${pkgdir}/usr/
  rm -f ${pkgdir}/usr/bin/*-config
  cp -rf ${srcdir}/dest/usr/share/locale ${pkgdir}/usr/share/
}

package_libgpg-error-devel() {
  pkgdesc="Libgpg-error headers and libraries"
  groups=('development')
  options=('staticlibs')
  depends=('libiconv-devel' 'gettext-devel')

  mkdir -p ${pkgdir}/usr/{bin,share}
  cp -f ${srcdir}/dest/usr/bin/*-config ${pkgdir}/usr/bin/
  cp -rf ${srcdir}/dest/usr/include ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/lib ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/share/aclocal ${pkgdir}/usr/share/
  cp -rf ${srcdir}/dest/usr/share/common-lisp ${pkgdir}/usr/share/
}
